package com.jh.channel.pojo.fastsilver;

import java.util.Objects;

import static com.google.common.base.Strings.isNullOrEmpty;

public enum OrderStatus  {

    /** 待支付 */
    WAITING("WAITING", "\u5f85\u652f\u4ed8"),

    /** 待处理 */
    PENDING("PENDING", "\u5f85\u5904\u7406"),

    /** 支付中 */
    PROCESS("PROCESS", "\u652f\u4ed8\u4e2d"),

    /** 成功 */
    SUCCESS("SUCCESS", "\u6210\u529f"),

    /** 失败 */
    FAILURE("FAILURE", "\u5931\u8d25"),

    /** 未知 */
    UNKNOWN("UNKNOWN", "\u672a\u77e5"),

    /** 已退款 */
    REFUND("REFUND", "\u5df2\u9000\u6b3e"),
    ;
    final String value;
    final String desc;

    OrderStatus(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static OrderStatus of(String val) {
        return of(val, null);
    }

    public static OrderStatus of(String val, OrderStatus defaultStatus) {
        if (isNullOrEmpty(val)) {
            return defaultStatus;
        }
        val = val.toUpperCase();
        for (OrderStatus os : values()) {
            if (val.equals(os.getValue().toUpperCase())) {
                return os;
            }
        }
        return defaultStatus;
    }

}
